package com.ex.volley;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.android.volley.AuthFailureError;
import com.android.volley.RequestQueue;
import com.android.volley.VolleyError;
import com.android.volley.Request.Method;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.ex.util.AppUtils;
import com.example.androiddemo.App;
import com.example.androiddemo.Const;

/**
 * volley 请求辅助类
 * @author thduan
 * 2015-9-16 15:51:24
 */
public class VolleyHelper {
	
	/**
	 * post请求封装示例
	 * @param params
	 */
	public static void reqPost(Map<String, String> params) {
		stringReqPost(params);
	}
	
	private static void stringReqPost(final Map<String, String> params) {
		StringRequest stringRequest = new StringRequest(Method.POST, Const.HTTP_POST_URL, new Listener<String>() {

			@Override
			public void onResponse(String response) {
				AppUtils.toast(response);
			}
		}, new ErrorListener() {

			@Override
			public void onErrorResponse(VolleyError error) {
				AppUtils.volleyErrorHandle(error);
			}
		}) {
			@Override
			protected Map<String, String> getParams() throws AuthFailureError {
				return params;
			}
		};
		stringRequest.setShouldCache(false);
		App.getReqQueue().add(stringRequest);
	}

}
